package org.springframework.beans.factory.support;

import cn.hutool.core.bean.BeanException;
import org.springframework.beans.BaseException;
import org.springframework.beans.factory.config.BeanDefinition;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 山顶洞人郑某
 * @className DefaultListableBeanFactory.java 单列bean工厂
 * @date 2025 04 21
 */
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements BeanDefinitionRegistry {

    private Map<String, BeanDefinition> beanDefinitionMap = new HashMap<>();
    /**
     * 获取bean的基本信息
     *
     * @param beanName
     * @return bean的基本信息
     */
    @Override
    protected BeanDefinition getBeanDefinition(String beanName) {
        BeanDefinition beanDefinition = beanDefinitionMap.get(beanName);
        if (beanDefinition == null) {
            throw new BeanException("No bean named '" + beanName + "' is defined");
        }
        return beanDefinition;
    }

    @Override
    public void register(String beanName, Object bean) throws BaseException {

    }

    /**
     * 根据beanName和beanType获取bean
     *
     * @param beanName
     * @param beanType
     * @return
     * @throws BaseException bean不存在
     */
    @Override
    public <T> T getBean(String beanName, Class<T> beanType) throws BaseException {
        return null;
    }

    /**
     * 根据beanTyep获取bean
     *
     * @param beanType
     * @return
     * @throws BaseException
     */
    @Override
    public <T> T getBean(Class<T> beanType) throws BaseException {
        return null;
    }

    @Override
    public Boolean contanisBean(String name) {
        return null;
    }

    /**
     * 向注册表中注入bean信息
     *
     * @param beanName       bean名称
     * @param beanDefinition bean的基本信息
     */
    @Override
    public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {
       beanDefinitionMap.put(beanName,beanDefinition);
    }
}
